<?php

/**
 * This is the model class for table "gfmeasurementunit".
 *
 * The followings are the available columns in table 'gfmeasurementunit':
 * @property integer $MeasurementUnitID
 * @property string $MeasurementUnitName
 * @property string $MeasurementUnitNameShort
 * @property double $Multiplication
 * @property string $MultiplyUnit
 * @property integer $MeasurementUnitGroupID
 * @property integer $isActive
 * @property string $CreatedBy
 * @property string $CreatedOn
 * @property string $LastUpdateBy
 * @property string $LastUpdateOn
 *
 * The followings are the available model relations:
 * @property Gfmeasurementunitgroup $measurementUnitGroup
 * @property GfmeasurementunitWeight $multiplyUnit
 * @property GfmeasurementunitWeight[] $gfmeasurementunits
 * @property Mastershippingdistance[] $mastershippingdistances
 * @property Odsitemsdetail[] $odsitemsdetails
 * @property Odsitemsdetail[] $odsitemsdetails1
 */
class GfmeasurementunitWeight extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gfmeasurementunit';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('MeasurementUnitID, MeasurementUnitName, CreatedBy, CreatedOn', 'required'),
			array('MeasurementUnitID, MeasurementUnitGroupID, isActive', 'numerical', 'integerOnly'=>true),
			array('Multiplication', 'numerical'),
			array('MeasurementUnitName, CreatedBy, LastUpdateBy', 'length', 'max'=>50),
			array('MeasurementUnitNameShort, MultiplyUnit', 'length', 'max'=>10),
			array('LastUpdateOn', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('MeasurementUnitID, MeasurementUnitName, MeasurementUnitNameShort, Multiplication, MultiplyUnit, MeasurementUnitGroupID, isActive, CreatedBy, CreatedOn, LastUpdateBy, LastUpdateOn', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'measurementUnitGroup' => array(self::BELONGS_TO, 'Gfmeasurementunitgroup', 'MeasurementUnitGroupID'),
			'multiplyUnit' => array(self::BELONGS_TO, 'GfmeasurementunitWeight', 'MultiplyUnit'),
			'gfmeasurementunits' => array(self::HAS_MANY, 'GfmeasurementunitWeight', 'MultiplyUnit'),
			'mastershippingdistances' => array(self::HAS_MANY, 'Mastershippingdistance', 'DistanceMeasurementUnit'),
			'odsitemsdetails' => array(self::HAS_MANY, 'Odsitemsdetail', 'ItemMeasurementUnitIDReal'),
			'odsitemsdetails1' => array(self::HAS_MANY, 'Odsitemsdetail', 'ItemMeasurementUnitID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'MeasurementUnitID' => 'Measurement Unit',
			'MeasurementUnitName' => 'Measurement Unit Name',
			'MeasurementUnitNameShort' => 'Measurement Unit Name Short',
			'Multiplication' => 'Multiplication',
			'MultiplyUnit' => 'Multiply Unit',
			'MeasurementUnitGroupID' => 'Measurement Unit Group',
			'isActive' => 'Is Active',
			'CreatedBy' => 'Created By',
			'CreatedOn' => 'Created On',
			'LastUpdateBy' => 'Last Update By',
			'LastUpdateOn' => 'Last Update On',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('MeasurementUnitID',$this->MeasurementUnitID);
		$criteria->compare('MeasurementUnitName',$this->MeasurementUnitName,true);
		$criteria->compare('MeasurementUnitNameShort',$this->MeasurementUnitNameShort,true);
		$criteria->compare('Multiplication',$this->Multiplication);
		$criteria->compare('MultiplyUnit',$this->MultiplyUnit,true);
		$criteria->compare('MeasurementUnitGroupID',$this->MeasurementUnitGroupID);
		$criteria->compare('isActive',$this->isActive);
		$criteria->compare('CreatedBy',$this->CreatedBy,true);
		$criteria->compare('CreatedOn',$this->CreatedOn,true);
		$criteria->compare('LastUpdateBy',$this->LastUpdateBy,true);
		$criteria->compare('LastUpdateOn',$this->LastUpdateOn,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return GfmeasurementunitWeight the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
